var rimraf = require('rimraf');
var t = require('tap');

var fs = require('fs');
var fill = require('./fill.js');
t.test('initial clean', function (t) {
  rimraf.sync(__dirname + '/target');
  t.throws(function () {
    fs.statSync(__dirname + '/target');
  })
  t.end();
})
t.test('sync remove', function (t) {
  fill();
  t.ok(fs.statSync(__dirname+'/target').isDirectory());
  rimraf.sync(__dirname+'/target');
  t.throws(function () {
    fs.statSync(__dirname+'/target')
  })
  t.end()
})

t.test('glob', function (t) {
  t.plan(2)
  t.test('async', function (t) {
    fill()
    var glob = require('glob')
    var pattern = __dirname + '/target/f-*'
    var before = glob.sync(pattern)
    t.notEqual(before.length, 0)
    rimraf(pattern, function (er) {
      if (er)
        throw er
      var after = glob.sync(pattern)
      t.same(after, [])
      rimraf.sync(__dirname + '/target')
      t.end()
    })
  })
  t.test('sync', function (t) {
    fill()
    var glob = require('glob')
    var pattern = __dirname + '/target/f-*'
    var before = glob.sync(pattern)
    t.notEqual(before.length, 0)
    rimraf.sync(pattern)
    var after = glob.sync(pattern)
    t.same(after, [])
    rimraf.sync(__dirname + '/target')
    t.end()
  })
})
